<?php
/**
 * Joomla! 1.5 component jhtraq
 *
 * @version $Id: controller.php 2010-03-09 08:28:06 svn $
 * @author JHShop
 * @package Joomla
 * @subpackage jhtraq
 * @license GNU/GPL
 *
 * Traq type system for Joomla
 *
 */

// no direct access
defined('_JEXEC') or die('Restricted access');

jimport('joomla.application.component.controller');
require_once( JPATH_ADMINISTRATOR.DS.'components'.DS.'com_jhtraq'.DS.'helpers'.DS.'helper.php' );

/**
 * jhtraq Component Controller
 */
class JhtraqController extends JController {
	function display() {
        // Make sure we have a default view
        
		$this->mergeUser();
		
		if( !JRequest::getVar( 'view' )) {
		    JRequest::setVar('view', 'jhtraq' );
        }
		
		parent::display();
	}
	
	function mergeUser()
	{
		
		$user =& JFactory::getUser();
		$db =& JFactory::getDBO();
		
		$uid = (int)$user->id;
		if($uid > 0)
		{
			$db->setQuery("Select * from #__jhtraq_users where id=$uid");
			$tuser = $db->loadObject();
			if(!$tuser->id)
			{
				$db->setQuery("Insert into #__jhtraq_users(`id`,`group_id`) values('$uid','2')"); //hardcoded - make members -> members
				$db->query();
			}
		}
		
	}
}
?>